{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Josephson Junction QComponent Demo Notebook"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This demo notebook describes two types of Josephson Junction (JJ) qcomponents available in Qiskit Metal, including a \"Manhattan\"-style JJ and a \"Dolan\"-style JJ. In addition, we demonstrate how to insert these realistic JJ structures in between the capacative pads of the transmon pocket qcomponent, forming a realistic qubit design. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's start to importing some key modules:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import qiskit_metal as metal\n",
    "from qiskit_metal import designs, draw\n",
    "from qiskit_metal import MetalGUI, Dict #, open_docs"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Next, we'll fire up the Qiskit Metal GUI: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "design = designs.DesignPlanar()\n",
    "gui = MetalGUI(design)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Next, let's see what a Manhattan-style JJ looks like. We'll import the qcomponent and place it in our design, calling it \"JJ1\":"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit_metal.qlibrary.qubits.JJ_Manhattan import jj_manhattan\r\n",
    "design.overwrite_enabled = True\r\n",
    "jj1 = jj_manhattan(design, 'JJ1', options=dict())\r\n",
    "gui.rebuild()\r\n",
    "gui.autoscale()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can take a screenshot of the GUI to see what our JJ looks like up close::"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "gui.rebuild()\r\n",
    "gui.autoscale()\r\n",
    "gui.edit_component('JJ1')\r\n",
    "gui.zoom_on_components(['JJ1'])\r\n",
    "gui.highlight_components(['JJ1'])\r\n",
    "gui.screenshot()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note that you'll have to zoom in to see the JJ qcomponent since the default dimensions are quite small (micrometers instead of mm!) For the Manhattan-style junction, we see two crossing rectangles each connected to a larger rectangular pad. All of the metal is part of the same layer, as opposed to the two-layer Dolan-style design that we'll see below. \n",
    "\n",
    "Also note that for both JJ qcomponents, the coordinates (pos_x, pos_y) define the lower-left corner of the bottom rectangle. Since the default values of these coordinates are zero, we see that the bottom left corner is at the origin. \n",
    "\n",
    "Now, let's take a look at a Dolan-style JJ qcomponent design. We'll call this one \"JJ2\" and we'll place it such that the bottom left corner is at the coordinate (0.1, 0.0) so that we can look at the two qcomponents side-by-side in our design: "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit_metal.qlibrary.qubits.JJ_Dolan import jj_dolan\r\n",
    "design.overwrite_enabled = True\r\n",
    "jj2 = jj_dolan(design, 'JJ2', options=dict(pos_x=\"0.1\", pos_y=\"0.0\"))\r\n",
    "gui.rebuild()\r\n",
    "gui.autoscale()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can again take a GUI screenshot to see how this JJ differs from the Manhattan-style one:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "gui.rebuild()\r\n",
    "gui.autoscale()\r\n",
    "gui.edit_component('JJ2')\r\n",
    "gui.zoom_on_components(['JJ2'])\r\n",
    "gui.highlight_components(['JJ2'])\r\n",
    "gui.screenshot()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You'll notice that the Dolan-style JJ has a similar structure as the Manhattan-style JJ but the second set of rectangles is translated so that they no longer overlap with the first pair of rectangles. In addition, we see a smaller rectangle drawn which is actually defined to be on a different metal layer than the other rectangles. This reflects the fact that in Dolan-style JJ fabrication, there are two separate metal levels used in the shadow masking process. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Inserting Josephson Junctions into a Transmon Qubit Design"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In a realistic quantum chip design, the JJs would be located in between the large pads of the transmon pocket. Before we show what this would actually look like, let's delete the two JJs that we've drawn and start from scratch. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "jj1.delete()\n",
    "jj2.delete()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You may have to hit the \"Replot\" button in the GUI after deleting. Now, let's create an instance of a basic transmon pocket qcomponent, using all default settings:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit_metal.qlibrary.qubits.transmon_pocket import TransmonPocket\n",
    "design.overwrite_enabled = True\n",
    "q1 = TransmonPocket(design, 'qubit1', options=dict())\n",
    "gui.rebuild()\n",
    "gui.autoscale()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "When we zoom in and see that the middle of the \"JJ region\" of the transmon pocket is at the origin. This is the region we will place our actual JJ qcomponent. Since we want the larger rectangular pads of the JJ qcomponent to overlap with the large rectangular pads of the transmon pocket, we'll have to pick a suitable (x,y) coordinate for the JJ. Here's an example of placing the Manhattan-style JJ in this region:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit_metal.qlibrary.qubits.JJ_Manhattan import jj_manhattan\r\n",
    "design.overwrite_enabled = True\r\n",
    "jj1 = jj_manhattan(design, 'JJ1', options=dict(pos_x=\"-0.015\", pos_y=\"-0.02\"))\r\n",
    "gui.rebuild()\r\n",
    "gui.autoscale()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can take a GUI screenshot to see how the transmon qubit looks with the JJ inserted:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "gui.rebuild()\r\n",
    "gui.autoscale()\r\n",
    "gui.edit_component('qubit1')\r\n",
    "gui.zoom_on_components(['qubit1'])\r\n",
    "gui.screenshot()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can zoom in on the actual JJ to see how the pads overlap with the large rectangular pads of the transmon:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "gui.rebuild()\r\n",
    "gui.autoscale()\r\n",
    "gui.edit_component('JJ1')\r\n",
    "gui.zoom_on_components(['JJ1'])\r\n",
    "gui.screenshot()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In the same way, we can place another transmon pocket at (1,1) and then place a Dolan-style JJ inside:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "design.overwrite_enabled = True\r\n",
    "q2 = TransmonPocket(design, 'qubit2', options=dict(pos_x=\"1.0\"))\r\n",
    "jj2 = jj_dolan(design, 'JJ2', options=dict(pos_x=\"0.985\", pos_y=\"-0.02\"))\r\n",
    "gui.rebuild()\r\n",
    "gui.autoscale()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's take a screenshot to see what the transmon qubit looks like with the JJ inserted:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "gui.rebuild()\r\n",
    "gui.autoscale()\r\n",
    "gui.edit_component('qubit2')\r\n",
    "gui.zoom_on_components(['qubit2'])\r\n",
    "gui.screenshot()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Lastly, we can zoom in even more to see how the Dolan-style JJ looks while connected to the pads of the transmon:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "gui.rebuild()\r\n",
    "gui.autoscale()\r\n",
    "gui.edit_component('JJ2')\r\n",
    "gui.zoom_on_components(['JJ2'])\r\n",
    "gui.screenshot()"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "3c543aac259cb5d300c63f5c4b30daf72526e10e2454451f45e9cc4261aaa61c"
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}